home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / sndhrdw / sega.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  15KB  |  678 lines

  1. #include "driver.h"
  2.  
  3. /* History:
  4.  
  5.  
  6.  
  7.  * 4/25/99 Tac-Scan now makes Credit Noises with $2c                    (Jim Hernandez)
  8.  * 4/9/99 Zektor Discrete Sound Support mixed with voice samples.       (Jim Hernandez)
  9.           Zektor uses some Eliminator sounds.
  10.  
  11.  * 2/5/99 Extra Life sound constant found $1C after fixing main driver. (Jim Hernandez)
  12.  * 1/29/99 Supports Tac Scan new 44.1Khz sample set.                    (Jim Hernandez)
  13.  
  14.  * -Stuff to do -
  15.  * Find hex bit for warp.wav sound calls.
  16.  *
  17.  * 2/05/98 now using the new sample_*() functions. BW
  18.  *
  19.  */
  20.  
  21. /*
  22.     Tac/Scan sound constants
  23.  
  24.     There are some sounds that are unknown:
  25.     $09 Tunnel Warp Sound?
  26.     $0a
  27.     $0b Formation Change
  28.         $0c
  29.         $0e
  30.         $0f
  31.         $1c 1up (Extra Life)
  32.         $2c Credit
  33.         $30 - $3f  Hex numbers for ship position flight sounds
  34.     $41
  35.  
  36.     Some sound samples are missing:
  37.        - I use the one bullet and one explosion sound for all 3 for example.
  38.  
  39. Star Trk Sounds (USB Loaded from 5400 in main EPROMs)
  40.  
  41. 8     PHASER
  42. a     PHOTON
  43. e     TARGETING
  44. 10    DENY
  45. 12    SHEILD HIT
  46. 14    ENTERPRISE HIT
  47. 16    ENT EXPLOSION
  48. 1a    KLINGON EXPLOSION
  49. 1c    DOCK
  50. 1e    STARBASE HIT
  51. 11    STARBASE RED
  52. 22    STARBASE EXPLOSION
  53. 24    SMALL BONUS
  54. 25    LARGE BONUS
  55. 26    STARBASE INTRO
  56. 27    KLINGON INTRO
  57. 28    ENTERPRISE INTRO
  58. 29    PLAYER CHANGE
  59. 2e    KLINGON FIRE
  60. 4,5   IMPULSE
  61. 6,7   WARP
  62. c,d   RED ALERT
  63. 18,2f WARP SUCK
  64. 19,2f SAUCER EXIT
  65. 2c,21 NOMAD MOTION
  66. 2d,21 NOMAD STOPPED
  67. 2b    COIN DROP MUSIC
  68. 2a    HIGH SCORE MUSIC
  69.  
  70.  
  71. Eliminator Sound Board (800-3174)
  72. ---------------------------------
  73.  
  74. inputs
  75. 0x3c-0x3f
  76.  
  77. d0 speech ready
  78.  
  79. outputs ( 0 = ON)
  80.  
  81. 0x3e (076)
  82.  
  83. d7      torpedo 2
  84. d6      torpedo 1
  85. d5      bounce
  86. d4      explosion 3
  87. d3      explosion 2
  88. d2      explosion 1
  89. d1      fireball
  90. d0      -
  91.  
  92. 0x3f (077)
  93.  
  94. d7      background msb
  95. d6      background lsb
  96. d5      enemy ship
  97. d4      skitter
  98. d3      thrust msb
  99. d2      thrust lsb
  100. d1      thrust hi
  101. d0      thrust lo
  102.  
  103. Space Fury Sound Board (800-0241)
  104. ---------------------------------
  105.  
  106. 0x3e (076) (0 = ON)
  107.  
  108. d7      partial warship, low frequency oscillation
  109. d6      star spin
  110. d5      -
  111. d4      -
  112. d3      -
  113. d2      thrust, low frequency noise
  114. d1      fire, metalic buzz
  115. d0      craft scale, rising tone
  116.  
  117. 0x3f (077)
  118.  
  119. d7      -
  120. d6      -
  121. d5      docking bang
  122. d4      large explosion
  123. d3      small explosion, low frequency noise
  124. d2      fireball
  125. d1      shot
  126. d0      crafts joining
  127.  
  128. */
  129.  
  130. /* Some Tac/Scan sound constants */
  131. #define    shipStop 0x10
  132. #define shipLaser 0x18
  133. #define    shipExplosion 0x20
  134. #define    shipDocking 0x28
  135. #define    shipRoar 0x40
  136. #define    tunnelHigh 0x48
  137. #define    stingerThrust 0x50
  138. #define    stingerLaser 0x51
  139. #define    stingerStop 0x52
  140. #define    stingerExplosion 0x54
  141. #define    enemyBullet0 0x61
  142. #define    enemyBullet1 0x62
  143. #define    enemyBullet2 0x63
  144. #define    enemyExplosion0 0x6c
  145. #define    enemyExplosion1 0x6d
  146. #define    enemyExplosion2 0x6e
  147. #define tunnelw   0x09
  148. #define flight1   0x36
  149. #define flight2   0x3b
  150. #define flight3   0x3d
  151. #define flight4   0x3e
  152. #define flight5   0x3f
  153. #define warp      0x37
  154. #define formation 0x0b
  155. #define nothing1  0x1a
  156. #define nothing2  0x1b
  157. #define extralife 0x1c
  158. #define credit    0x2c
  159.  
  160.  
  161. #define    kVoiceShipRoar 5
  162. #define    kVoiceShip 1
  163. #define    kVoiceTunnel 2
  164. #define    kVoiceStinger 3
  165. #define    kVoiceEnemy 4
  166. #define kVoiceExtra 8
  167. #define kVoiceForm 7
  168. #define kVoiceWarp 6
  169. #define kVoiceExtralife 9
  170.  
  171. static int roarPlaying;    /* Is the ship roar noise playing? */
  172.  
  173. /*
  174.  * The speech samples are queued in the order they are received
  175.  * in sega_sh_speech_w (). sega_sh_update () takes care of playing
  176.  * and updating the sounds in the order they were queued.
  177.  */
  178.  
  179. #define MAX_SPEECH      16      /* Number of speech samples which can be queued */
  180. #define NOT_PLAYING    -1    /* Queue position empty */
  181.  
  182. static int queue[MAX_SPEECH];
  183. static int queuePtr = 0;
  184.  
  185. int sega_sh_start (const struct MachineSound *msound)
  186. {
  187.     int i;
  188.  
  189.     for (i = 0; i < MAX_SPEECH; i ++)
  190.         queue[i] = NOT_PLAYING;
  191.  
  192.     return 0;
  193. }
  194.  
  195. READ_HANDLER( sega_sh_r )
  196. {
  197.     /* 0x80 = universal sound board ready */
  198.     /* 0x01 = speech ready */
  199.  
  200.     if (sample_playing(0))
  201.         return 0x81;
  202.     else
  203.         return 0x80;
  204. }
  205.  
  206. WRITE_HANDLER( sega_sh_speech_w )
  207. {
  208.     int sound;
  209.  
  210.     sound = data & 0x7f;
  211.     /* The sound numbers start at 1 but the sample name array starts at 0 */
  212.     sound --;
  213.  
  214.     if (sound < 0)    /* Can this happen? */
  215.         return;
  216.  
  217.     if (!(data & 0x80))
  218.        {
  219.         /* This typically comes immediately after a speech command. Purpose? */
  220.         return;
  221.     }
  222.        else if (Machine->samples != 0 && Machine->samples->sample[sound] != 0)
  223.        {
  224.         int newPtr;
  225.  
  226.         /* Queue the new sound */
  227.         newPtr = queuePtr;
  228.         while (queue[newPtr] != NOT_PLAYING)
  229.            {
  230.             newPtr ++;
  231.             if (newPtr >= MAX_SPEECH)
  232.                 newPtr = 0;
  233.             if (newPtr == queuePtr)
  234.                {
  235.                 /* The queue has overflowed. Oops. */
  236.                 logerror("*** Queue overflow! queuePtr: %02d\n", queuePtr);
  237.                 return;
  238.             }
  239.         }
  240.         queue[newPtr] = sound;
  241.     }
  242. }
  243.  
  244. void sega_sh_update (void)
  245. {
  246.     int sound;
  247.  
  248.     /* if a sound is playing, return */
  249.     if (sample_playing(0)) return;
  250.  
  251.     /* Check the queue position. If a sound is scheduled, play it */
  252.     if (queue[queuePtr] != NOT_PLAYING)
  253.        {
  254.         sound = queue[queuePtr];
  255.         sample_start(0, sound, 0);
  256.  
  257.         /* Update the queue pointer to the next one */
  258.         queue[queuePtr] = NOT_PLAYING;
  259.         ++ queuePtr;
  260.         if (queuePtr >= MAX_SPEECH)
  261.             queuePtr = 0;
  262.         }
  263.     }
  264.  
  265. int tacscan_sh_start (const struct MachineSound *msound)
  266. {
  267.     roarPlaying = 0;
  268.     return 0;
  269. }
  270.  
  271. WRITE_HANDLER( tacscan_sh_w )
  272. {
  273.     int sound;   /* index into the sample name array in drivers/sega.c */
  274.     int voice=0; /* which voice to play the sound on */
  275.     int loop;    /* is this sound continuous? */
  276.  
  277.     loop = 0;
  278.     switch (data)
  279.        {
  280.         case shipRoar:
  281.             /* Play the increasing roar noise */
  282.             voice = kVoiceShipRoar;
  283.             sound = 0;
  284.             roarPlaying = 1;
  285.             break;
  286.         case shipStop:
  287.             /* Play the decreasing roar noise */
  288.             voice = kVoiceShipRoar;
  289.             sound = 2;
  290.             roarPlaying = 0;
  291.             break;
  292.         case shipLaser:
  293.             voice = kVoiceShip;
  294.             sound = 3;
  295.             break;
  296.         case shipExplosion:
  297.             voice = kVoiceShip;
  298.             sound = 4;
  299.             break;
  300.         case shipDocking:
  301.             voice = kVoiceShip;
  302.             sound = 5;
  303.             break;
  304.         case tunnelHigh:
  305.             voice = kVoiceTunnel;
  306.             sound = 6;
  307.             break;
  308.         case stingerThrust:
  309.             voice = kVoiceStinger;
  310.             sound = 7;
  311.                         loop = 0; //leave off sound gets stuck on
  312.             break;
  313.         case stingerLaser:
  314.             voice = kVoiceStinger;
  315.             sound = 8;
  316.                         loop = 0;
  317.             break;
  318.         case stingerExplosion:
  319.             voice = kVoiceStinger;
  320.             sound = 9;
  321.             break;
  322.         case stingerStop:
  323.             voice = kVoiceStinger;
  324.             sound = -1;
  325.             break;
  326.         case enemyBullet0:
  327.         case enemyBullet1:
  328.         case enemyBullet2:
  329.             voice = kVoiceEnemy;
  330.             sound = 10;
  331.             break;
  332.         case enemyExplosion0:
  333.         case enemyExplosion1:
  334.         case enemyExplosion2:
  335.             voice = kVoiceTunnel;
  336.             sound = 11;
  337.             break;
  338.                 case tunnelw: voice = kVoiceShip;
  339.                               sound = 12;
  340.                               break;
  341.                 case flight1: voice = kVoiceExtra;
  342.                               sound = 13;
  343.                               break;
  344.                 case flight2: voice = kVoiceExtra;
  345.                               sound = 14;
  346.                               break;
  347.                 case flight3: voice = kVoiceExtra;
  348.                               sound = 15;
  349.                               break;
  350.                 case flight4: voice = kVoiceExtra;
  351.                               sound = 16;
  352.                               break;
  353.                 case flight5: voice = kVoiceExtra;
  354.                               sound = 17;
  355.                               break;
  356.         case formation:
  357.                               voice = kVoiceForm;
  358.                                 sound = 18;
  359.                   break;
  360.                case warp:    voice = kVoiceExtra;
  361.                               sound = 19;
  362.                               break;
  363.                 case extralife: voice = kVoiceExtralife;
  364.                                 sound = 20;
  365.                                 break;
  366.                 case credit:    voice = kVoiceExtra;
  367.                                 sound = 21;
  368.                                 break;
  369.  
  370.                 default:
  371.  
  372.             /* don't play anything */
  373.             sound = -1;
  374.             break;
  375.                       }
  376.     if (sound != -1)
  377.        {
  378.         sample_stop (voice);
  379.         /* If the game is over, turn off the stinger noise */
  380.         if (data == shipStop)
  381.             sample_stop (kVoiceStinger);
  382.         sample_start (voice, sound, loop);
  383.     }
  384. }
  385.  
  386. void tacscan_sh_update (void)
  387. {
  388.     /* If the ship roar has started playing but the sample stopped */
  389.     /* play the intermediate roar noise */
  390.  
  391.     if ((roarPlaying) && (!sample_playing(kVoiceShipRoar)))
  392.         sample_start (kVoiceShipRoar, 1, 1);
  393. }
  394.  
  395.  
  396. WRITE_HANDLER( elim1_sh_w )
  397. {
  398.     data ^= 0xff;
  399.  
  400.     /* Play fireball sample */
  401.     if (data & 0x02)
  402.         sample_start (0, 0, 0);
  403.  
  404.     /* Play explosion samples */
  405.     if (data & 0x04)
  406.         sample_start (1, 10, 0);
  407.     if (data & 0x08)
  408.         sample_start (1, 9, 0);
  409.     if (data & 0x10)
  410.         sample_start (1, 8, 0);
  411.  
  412.     /* Play bounce sample */
  413.     if (data & 0x20)
  414.        {
  415.         if (sample_playing(2))
  416.             sample_stop (2);
  417.         sample_start (2, 1, 0);
  418.     }
  419.  
  420.     /* Play lazer sample */
  421.     if (data & 0xc0)
  422.        {
  423.         if (sample_playing(3))
  424.             sample_stop (3);
  425.         sample_start (3, 5, 0);
  426.     }
  427. }
  428.  
  429. WRITE_HANDLER( elim2_sh_w )
  430. {
  431.     data ^= 0xff;
  432.  
  433.     /* Play thrust sample */
  434.     if (data & 0x0f)
  435.         sample_start (4, 6, 0);
  436.     else
  437.         sample_stop (4);
  438.  
  439.     /* Play skitter sample */
  440.     if (data & 0x10)
  441.         sample_start (5, 2, 0);
  442.  
  443.     /* Play eliminator sample */
  444.     if (data & 0x20)
  445.         sample_start (6, 3, 0);
  446.  
  447.     /* Play electron samples */
  448.     if (data & 0x40)
  449.         sample_start (7, 7, 0);
  450.     if (data & 0x80)
  451.         sample_start (7, 4, 0);
  452. }
  453.  
  454.  
  455. WRITE_HANDLER( zektor1_sh_w )
  456. {
  457.     data ^= 0xff;
  458.  
  459.     /* Play fireball sample */
  460.     if (data & 0x02)
  461.                 sample_start (0, 19, 0);
  462.  
  463.     /* Play explosion samples */
  464.     if (data & 0x04)
  465.                 sample_start (1, 29, 0);
  466.      if (data & 0x08)
  467.                   sample_start (1, 28, 0);
  468.      if (data & 0x10)
  469.                   sample_start (1, 27, 0);
  470.  
  471.     /* Play bounce sample */
  472.     if (data & 0x20)
  473.        {
  474.                 if (sample_playing(2))
  475.                         sample_stop (2);
  476.                 sample_start (2, 20, 0);
  477.     }
  478.  
  479.     /* Play lazer sample */
  480.     if (data & 0xc0)
  481.        {
  482.         if (sample_playing(3))
  483.             sample_stop (3);
  484.                 sample_start (3, 24, 0);
  485.     }
  486. }
  487.  
  488. WRITE_HANDLER( zektor2_sh_w )
  489. {
  490.     data ^= 0xff;
  491.  
  492.     /* Play thrust sample */
  493.     if (data & 0x0f)
  494.             sample_start (4, 25, 0);
  495.     else
  496.         sample_stop (4);
  497.  
  498.     /* Play skitter sample */
  499.     if (data & 0x10)
  500.                 sample_start (5, 21, 0);
  501.  
  502.     /* Play eliminator sample */
  503.     if (data & 0x20)
  504.                 sample_start (6, 22, 0);
  505.  
  506.     /* Play electron samples */
  507.     if (data & 0x40)
  508.                 sample_start (7, 40, 0);
  509.     if (data & 0x80)
  510.                 sample_start (7, 41, 0);
  511. }
  512.  
  513.  
  514.  
  515. WRITE_HANDLER( startrek_sh_w )
  516. {
  517.     switch (data)
  518.        {
  519.         case 0x08: /* phaser - trek1.wav */
  520.             sample_start (1, 0x17, 0);
  521.             break;
  522.         case 0x0a: /* photon - trek2.wav */
  523.             sample_start (1, 0x18, 0);
  524.             break;
  525.         case 0x0e: /* targeting - trek3.wav */
  526.             sample_start (1, 0x19, 0);
  527.             break;
  528.         case 0x10: /* dent - trek4.wav */
  529.             sample_start (2, 0x1a, 0);
  530.             break;
  531.         case 0x12: /* shield hit - trek5.wav */
  532.             sample_start (2, 0x1b, 0);
  533.             break;
  534.         case 0x14: /* enterprise hit - trek6.wav */
  535.             sample_start (2, 0x1c, 0);
  536.             break;
  537.         case 0x16: /* enterprise explosion - trek7.wav */
  538.             sample_start (2, 0x1d, 0);
  539.             break;
  540.         case 0x1a: /* klingon explosion - trek8.wav */
  541.             sample_start (2, 0x1e, 0);
  542.             break;
  543.         case 0x1c: /* dock - trek9.wav */
  544.             sample_start (1, 0x1f, 0);
  545.             break;
  546.         case 0x1e: /* starbase hit - trek10.wav */
  547.             sample_start (1, 0x20, 0);
  548.             break;
  549.         case 0x11: /* starbase red - trek11.wav */
  550.             sample_start (1, 0x21, 0);
  551.             break;
  552.         case 0x22: /* starbase explosion - trek12.wav */
  553.             sample_start (2, 0x22, 0);
  554.             break;
  555.         case 0x24: /* small bonus - trek13.wav */
  556.             sample_start (3, 0x23, 0);
  557.             break;
  558.         case 0x25: /* large bonus - trek14.wav */
  559.             sample_start (3, 0x24, 0);
  560.             break;
  561.         case 0x26: /* starbase intro - trek15.wav */
  562.             sample_start (1, 0x25, 0);
  563.             break;
  564.         case 0x27: /* klingon intro - trek16.wav */
  565.             sample_start (1, 0x26, 0);
  566.             break;
  567.         case 0x28: /* enterprise intro - trek17.wav */
  568.             sample_start (1, 0x27, 0);
  569.             break;
  570.         case 0x29: /* player change - trek18.wav */
  571.             sample_start (1, 0x28, 0);
  572.             break;
  573.         case 0x2e: /* klingon fire - trek19.wav */
  574.             sample_start (2, 0x29, 0);
  575.             break;
  576.         case 0x04: /* impulse start - trek20.wav */
  577.             sample_start (3, 0x2a, 0);
  578.             break;
  579.         case 0x06: /* warp start - trek21.wav */
  580.             sample_start (3, 0x2b, 0);
  581.             break;
  582.         case 0x0c: /* red alert start - trek22.wav */
  583.             sample_start (4, 0x2c, 0);
  584.             break;
  585.         case 0x18: /* warp suck - trek23.wav */
  586.             sample_start (4, 0x2d, 0);
  587.             break;
  588.         case 0x19: /* saucer exit - trek24.wav */
  589.             sample_start (4, 0x2e, 0);
  590.             break;
  591.         case 0x2c: /* nomad motion - trek25.wav */
  592.             sample_start (5, 0x2f, 0);
  593.             break;
  594.         case 0x2d: /* nomad stopped - trek26.wav */
  595.             sample_start (5, 0x30, 0);
  596.             break;
  597.         case 0x2b: /* coin drop music - trek27.wav */
  598.             sample_start (1, 0x31, 0);
  599.             break;
  600.         case 0x2a: /* high score music - trek28.wav */
  601.             sample_start (1, 0x32, 0);
  602.             break;
  603.     }
  604. }
  605.  
  606. WRITE_HANDLER( spacfury1_sh_w )
  607. {
  608.     data ^= 0xff;
  609.  
  610.     /* craft growing */
  611.     if (data & 0x01)
  612.         sample_start (1, 0x15, 0);
  613.  
  614.     /* craft moving */
  615.     if (data & 0x02)
  616.        {
  617.         if (!sample_playing(2))
  618.             sample_start (2, 0x16, 1);
  619.     }
  620.     else
  621.         sample_stop (2);
  622.  
  623.     /* Thrust */
  624.     if (data & 0x04)
  625.        {
  626.         if (!sample_playing(3))
  627.             sample_start (3, 0x19, 1);
  628.     }
  629.     else
  630.         sample_stop (3);
  631.  
  632.     /* star spin */
  633.     if (data & 0x40)
  634.         sample_start (4, 0x1d, 0);
  635.  
  636.     /* partial warship? */
  637.     if (data & 0x80)
  638.         sample_start (4, 0x1e, 0);
  639.  
  640. }
  641.  
  642. WRITE_HANDLER( spacfury2_sh_w )
  643. {
  644.     if (Machine->samples == 0) return;
  645.  
  646.     data ^= 0xff;
  647.  
  648.     /* craft joining */
  649.     if (data & 0x01)
  650.         sample_start (5, 0x17, 0);
  651.  
  652.     /* ship firing */
  653.     if (data & 0x02)
  654.        {
  655.         if (sample_playing(6))
  656.             sample_stop(6);
  657.         sample_start(6, 0x18, 0);
  658.  
  659.         }
  660.  
  661.     /* fireball */
  662.     if (data & 0x04)
  663.         sample_start (7, 0x1b, 0);
  664.  
  665.     /* small explosion */
  666.     if (data & 0x08)
  667.         sample_start (7, 0x1b, 0);
  668.     /* large explosion */
  669.     if (data & 0x10)
  670.         sample_start (7, 0x1a, 0);
  671.  
  672.     /* docking bang */
  673.     if (data & 0x20)
  674.         sample_start (8, 0x1c, 0);
  675.  
  676. }
  677.  
  678.